/* 
 *  Copyright 2012 CodeMagi, Inc.
 * 
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package com.codemagi.servlets.content.model;

import com.codemagi.servlets.model.Sortable;
import java.io.Serializable;
import java.util.*;

/**
 * Models an in-page promo
 *
 * @version 1.0
 * @author August Detlefsen for CodeMagi, Inc.
 */
public class Promo extends com.codemagi.servlets.model.BaseBean implements Serializable, Sortable {

    //members
    String body;
    ArrayList pages = new ArrayList();
    Integer sortOrder;

    //GETTERS AND SETTERS ------------------------------------

    public void setBody(String newValue) {
	body = newValue;
    }

    public String getBody() {
	return body;
    }

    public void setPages(ArrayList newValue) {
        pages = newValue;
    }

    public ArrayList getPages() {
        return pages;
    }

    public void setSortOrder(Integer newValue) {
        sortOrder = newValue;
    }

    public Integer getSortOrder() {
        return sortOrder;
    }



    //SPECIAL GETTERS AND SETTERS ------------------------------

    public boolean isInPage(NavPage page) {
	return pages.contains(page);
    }

    public List getPageIds() {
        List output = new ArrayList(pages.size());
        Iterator i  = pages.iterator();
        while (i.hasNext()) {
            NavPage n = (NavPage)i.next();
            output.add(n.getId());
        }
        return output;
    }

    public boolean isInPage(Integer pageId) {
        Iterator i  = pages.iterator();
        while (i.hasNext()) {
            NavPage n = (NavPage)i.next();
            if (n.getId().equals(pageId)) return true;
        }
        return false;
    }

}
